package com.kangyi.user.controller;

import com.kangyi.result.Result;
import com.kangyi.user.service.BannerService;
import com.kangyi.vo.BannerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/user/banner")
@Slf4j
@Api(tags = "banner相关接口")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/inquiry")
    @ApiOperation("查询number个banner")
    @Cacheable(cacheNames = "banner_", key = "'userInquiry_'+#number")
    public Result<List<BannerVO>> inquiryBanner(@RequestParam Integer number){
        log.info("查询最新的{}个banner",number);
        try {
            List<BannerVO> bannerVOList = bannerService.inquiryBanner(number);
            return Result.success(bannerVOList,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
